# ++++++++++ 简介 ++++++++++ #
# 文件名: PacketInfo.py
# 作者: 赵宗义, xinshengzzy@foxmail.com, 2021.04.17
# ---------- #


class PacketInfo:
    def __init__(self, line=None):
        if None == line:
            self.srcip = 0
            self.dstip = 0
            self.proto = 0
            self.sport = 0
            self.dport = 0
            self.length = 0
            self.ts = 0
        else:
            line = line.strip()
            items = line.split("\t")
            assert(7 == len(items))
            self.ts = float(items[0])
            self.srcip = int(items[1], 16)
            self.dstip = int(items[2], 16)
            self.proto = int(items[3], 16)
            self.sport = int(items[4], 16)
            self.dport = int(items[5], 16)
            self.length = int(items[6])

    def __str__(self):
        return "PacketInfo"

    def 提取流标识符(self):
        # print("提取流标识符(...)")
        return "%08x\t%08x\t%02x" % (self.srcip, self.dstip, self.proto)
        # return "%08x\t%08x\t%02x\t%04x\t%04x" % (self.srcip, self.dstip, self.proto, self.sport, self.dport)
